﻿Imports System.Data.OleDb
Public Class AddAudi
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub


    Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Dim myGUID = Guid.NewGuid()
        Dim newFileName As String = myGUID.ToString() & ".jpg"
        Dim fileLocationOnServerHardDisk = Request.MapPath("Pictures") & "/" & newFileName
        f_Picture.SaveAs(fileLocationOnServerHardDisk)
        Dim oleDbConn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("AudiCon").ConnectionString)
        Dim SqlString As String = "Insert into Ranges(Range,Picture,Details,ModelName,Info,ModelYear,Color,Engine,OwnerLocation) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9)"
        Dim cmd As OleDbCommand = New OleDbCommand(SqlString, oleDbConn)
        cmd.CommandType = CommandType.Text
        cmd.Parameters.AddWithValue("@f1", tb_range.Text)
        cmd.Parameters.AddWithValue("@f2", "Pictures/" & newFileName)
        cmd.Parameters.AddWithValue("@f3", tb_details.Text)
        cmd.Parameters.AddWithValue("@f4", tb_modelName.Text)
        cmd.Parameters.AddWithValue("@f5", tb_info.Text)
        cmd.Parameters.AddWithValue("@f6", tb_modelYear.Text)
        cmd.Parameters.AddWithValue("@f7", tb_color.Text)
        cmd.Parameters.AddWithValue("@f8", tb_engine.Text)
        cmd.Parameters.AddWithValue("@f9", tb_location.Text)

        oleDbConn.Open()
        cmd.ExecuteNonQuery()

        Response.Redirect("confirmation.aspx")

    End Sub
End Class